package lwh.servlet.progressmanage;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lwh.utils.DBHelper;
import lwh.utils.DateUtil;

public class CommitMessage extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String progressDate=new String(request.getParameter("progressDate").getBytes("ISO8859-1"),"UTF-8");
		String progress=new String(request.getParameter("progress").getBytes("ISO8859-1"),"UTF-8");
		String prj_progress_id=new String(request.getParameter("prj_progress_id").getBytes("ISO8859-1"),"UTF-8");
		String sql="UPDATE prj_progress SET prj_progress_date= ? ,prj_progress_percent= ? WHERE prj_progress_id=?";
		Connection con=null;
		int b=-1;;
		PreparedStatement stat=null;
		try {
			con=DBHelper.getConnection();
			stat=con.prepareStatement(sql);
			stat.setString(1, progressDate);
			stat.setInt(2, Integer.parseInt(progress));
			stat.setString(3, prj_progress_id);
			b=stat.executeUpdate();
			//con.commit();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				con.close();
				stat.close();
				if(b!=-1){
					response.getWriter().write(1);
				}else{
					response.getWriter().write(0);
				}
					
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
